﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using The_Chronicles_of_Asku;
using The_Chronicles_of_Asku.Characters;
using The_Chronicles_of_Asku.Areas.Tomb_Floors._1_10;
using The_Chronicles_of_Asku.Areas;

namespace The_Chronicles_of_Asku
{
    class CharacterLoadSave
    {
        public CharacterLoadSave()
        {

        }

        public void Save(Hero hero, Inn inn, Training firstTraining, FloorOne One, FloorTwo two, FloorThree three, FloorFour four, FloorFive five)
        {
            if (Directory.Exists(@"c:\TheChroniclesOfAsku\CharacterSaves") == false)
            {
                Directory.CreateDirectory(@"c:\TheChroniclesOfAsku\CharacterSaves");
            }
            StreamWriter file = new StreamWriter(@"c:\TheChroniclesOfAsku\CharacterSaves\PlayerData.txt");

            file.WriteLine(hero.health);
            file.WriteLine(hero.maxHealth);
            file.WriteLine(hero.minMagic);
            file.WriteLine(hero.maxMagic);
            //file.WriteLine(hero.Strength);
            //file.WriteLine(hero.defense);
            //file.WriteLine(hero.Agility);
            file.WriteLine(hero.xp);
            file.WriteLine(hero.level);
            file.WriteLine(hero.gold);
            file.WriteLine(hero.minAttack);
            file.WriteLine(hero.maxAttack);
            file.WriteLine(hero.Identifier);
            file.WriteLine(inn.completeFirst);
            file.WriteLine(firstTraining.complete);
            file.WriteLine(hero.minHeal);
            file.WriteLine(hero.maxHeal);
            file.WriteLine(hero.magicBonus);
            file.WriteLine(hero.attackBonus);
            file.WriteLine(hero.healBonus);
            file.WriteLine(hero.healthBonus);
            file.WriteLine(hero.armorBonus);
            file.WriteLine(hero.deathCount);
            file.WriteLine(hero.armor);
            file.WriteLine(hero.highestSurvival);

            /*foreach (string item in hero.items)
            {
                file.WriteLine(item);
            }*/

            file.Close();
            Console.WriteLine("Game Save successful");
            Console.WriteLine("Press enter to continue...");
            Console.ReadLine();
            Console.Clear();
        }



        public void Load(Hero hero, Inn inn, Training firstTraining, FloorOne one, FloorTwo two, FloorThree three, FloorFour four, FloorFive five)
        {
            bool done = false;
            string item;
            try
            {
                StreamReader file = new StreamReader(@"c:\TheChroniclesOfAsku\CharacterSaves\PlayerData.txt");

                hero.health = int.Parse(file.ReadLine());
                hero.maxHealth = int.Parse(file.ReadLine());
                hero.minMagic = int.Parse(file.ReadLine());
                hero.maxMagic = int.Parse(file.ReadLine());
                //hero.Strength = int.Parse(file.ReadLine());
                //hero.Defense = int.Parse(file.ReadLine());
                //hero.Agility = int.Parse(file.ReadLine());
                hero.xp = int.Parse(file.ReadLine());
                hero.level = int.Parse(file.ReadLine());
                hero.gold = int.Parse(file.ReadLine());
                hero.minAttack = int.Parse(file.ReadLine());
                hero.maxAttack = int.Parse(file.ReadLine());
                hero.Identifier = file.ReadLine();
                inn.completeFirst = bool.Parse(file.ReadLine());
                firstTraining.complete = bool.Parse(file.ReadLine());
                hero.minHeal = int.Parse(file.ReadLine());
                hero.maxHeal = int.Parse(file.ReadLine());
                hero.magicBonus = int.Parse(file.ReadLine());
                hero.attackBonus = int.Parse(file.ReadLine());
                hero.healBonus = int.Parse(file.ReadLine());
                hero.healthBonus = int.Parse(file.ReadLine());
                hero.armorBonus = int.Parse(file.ReadLine());
                hero.deathCount = int.Parse(file.ReadLine());
                hero.armor = int.Parse(file.ReadLine());
                hero.highestSurvival = int.Parse(file.ReadLine()); //RE-ENABLE FOR LAUNCH!!
                file.Close();
                Console.WriteLine("\nLoad Successful {0}.", hero.Identifier);
            }

            catch (Exception ex)
            {
                Console.WriteLine("\n\nYou must first create a character then save it.");
            }

            /*while (done == false)
            {
                item = file.ReadLine();

                if (item != null)
                {
                    hero.items.Add(item);
                }
                else
                {
                    done = true;
                }
            }*/


            Console.WriteLine("\n\nPress enter to continue...");
            Console.ReadLine();
            Console.Clear();
        }
    }
}